package com.operate.api.app.meal.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConstants;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.diagnosis.DiagnosisUtils;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradeWapPayResponse;
import com.github.pagehelper.PageInfo;
import com.operate.api.app.balance.domain.vo.AppOrderConsumeVO;
import com.operate.api.app.balance.domain.vo.AppOrderRechargeVO;
import com.operate.api.app.balance.service.IAppBalanceService;
import com.operate.api.app.meal.domain.vo.AppPackageSearchVO;
import com.operate.api.app.meal.domain.vo.AppPackageVO;
import com.operate.api.app.pay.domain.vo.RechargeRVO;
import com.operate.api.app.pay.service.IPayService;
import com.operate.api.base.ApiIndex;
import com.operate.api.base.IDEntity;
import com.operate.api.base.R;
import com.operate.api.base.RestPage;
import com.operate.api.operate.meal.service.IPackageService;
import com.operate.api.app.pay.domain.vo.RechargeVO;
import com.operate.api.operate.order.domain.vo.OrderRechargeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api( tags = ApiIndex.AppPackageController)
@RequestMapping(value = "/api/app/meal")
@RestController
public class AppMealController {

    @Autowired
    private IPackageService packageService;
    @Autowired
    IPayService payService;
    @Autowired
    private IAppBalanceService balanceService;


    @ApiOperation(value = "查询套餐列表")
    @GetMapping(value = "/package_list")
    public R<RestPage<List<AppPackageVO>>> package_list(
            @ApiParam(value = "查询参数") @ModelAttribute AppPackageSearchVO searchVO) {
        List<AppPackageVO> list = packageService.getAppList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }



    @ApiOperation(value = "创建充值订单[需要登录]")
    @PostMapping(value ="/add_recharge")
    @SaCheckLogin
    public R<RechargeRVO> add_recharge(@ApiParam(value = "查询参数") @RequestBody RechargeVO rechargeVO) {
        return new R(payService.addRecharge(rechargeVO));
    }


    @ApiOperation(value = "充值订单详情[需要登录]")
    @GetMapping(value = "/recharge_desc")
    @SaCheckLogin
    public R<AppOrderRechargeVO> consume_desc(@ApiParam(value = "订单ID") @Valid @ModelAttribute IDEntity id) {
        AppOrderRechargeVO resVO=balanceService.getRechargeDesc(id.getId());
        return new R(resVO);
    }

}